package com.springboot.service.system;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springboot.dao.SystemRoleMenuDao;
import com.springboot.entity.SystemRoleMenuEntity;
import com.springboot.returndata.dto.SaveRoleResourceTreeDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import jakarta.annotation.Resource;

/**
 * <p>
 * 角色资源表 服务实现类
 * </p>
 *
 * @author zyj
 * @since 2023-02-24
 */
@Service
@Slf4j
public class SystemRoleMenuService extends ServiceImpl<SystemRoleMenuDao, SystemRoleMenuEntity> {

        @Resource
        private SystemRoleMenuDao systemRoleMenuEntityDao;

        /**
         * description: 保存角色资源
          * @param saveRoleResourceTreeDto
         * @return: void
         * @author: zyj
         * @date: 2023/3/2
         */
        @Transactional(rollbackFor = Exception.class)
        public void saveRoleResourceTree(SaveRoleResourceTreeDto saveRoleResourceTreeDto){

                /**删除角色资源信息*/
                systemRoleMenuEntityDao.deleteByRoleId(Integer.parseInt(saveRoleResourceTreeDto.getRoleId()));

                /**保存角色资源*/
                systemRoleMenuEntityDao.saveRoleMenu(Integer.parseInt(saveRoleResourceTreeDto.getRoleId()), saveRoleResourceTreeDto.getMenuIds());
        }

}

